package cn.b.sky.message.service.impl;

import cn.b.sky.message.dao.MessageLogDao;
import cn.b.sky.message.enums.SendModeEnum;
import cn.b.sky.message.model.MessageLog;
import cn.b.sky.message.service.MessageSenderService;
import cn.b.sky.user.dao.UserDao;
import cn.b.sky.user.service.model.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
public class SmartWatchMessageSenderImpl implements MessageSenderService {
  
  @Resource
  UserDao userDao;
  
  @Resource
  MessageLogDao messageLogDao;

  @Override
  public void sentMessage(String messageCode, String message, String siteCode, String userCode) {
    UserInfo user = userDao.selectUser(siteCode, userCode);
    if (!StringUtils.isBlank(user.getSmartWatch())) {      
      //调用MI提供智能手表接口
      
      //新增消息日志
      MessageLog log = new MessageLog();
      log.setSiteCode(siteCode);
      log.setMessageCode(messageCode);
      log.setMessageContent(message);
      log.setSendUser("SYSTEM");
      log.setSendTime(new Date());
      log.setSendMode(SendModeEnum.SMARTWATCH.getValue());
      log.setReceiveUser(userCode);
      messageLogDao.insertMessageLog(log);
    }
  }

}
